using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ShootThemUp.Sources.PlayerInputs.WindowsPhone;
using ShootThemUp.Sources.AudioElements;
using Microsoft.Xna.Framework.Media;

namespace ShootThemUp.Sources.Screens
{
    /// <summary>
    /// This screen comes up when the player press the back button.
    /// </summary>
    class PauseScreen : MenuScreen
    {
        #region Fields 

        AccelerometerInput ai;

        #endregion
        /// <summary>
        /// Initializes a new instance of the <see cref="PauseScreen"/> class.
        /// </summary>
        public PauseScreen(AccelerometerInput ai)
            : base("Pause")
        {
            this.ai = ai;

            MenuEntry resume = new MenuEntry("Resume");
            MenuEntry quit = new MenuEntry("Quit");

            resume.Selected += ResumeMenuEntrySelected;
            quit.Selected += QuitEntrySelected;

            MenuEntries.Add(resume);
            MenuEntries.Add(new MenuEntry(""));
            MenuEntries.Add(quit);

            MediaPlayer.Pause();
        }

        /// <summary>
        /// Event handler for when the resume menu entry is selected.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The <see cref="ShootThemUp.Sources.Screens.PlayerIndexEventArgs"/> instance containing the event data.</param>
        private void ResumeMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            Audio audio = Audio.GetInstance;
            audio.Menu_Click.Play();
            this.OnCancel(e.PlayerIndex);
        }

        /// <summary>
        /// Event handler for when the quit menu entry is selected.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ShootThemUp.Sources.Screens.PlayerIndexEventArgs"/> instance containing the event data.</param>
        private void QuitEntrySelected(object sender, PlayerIndexEventArgs e)
        {            
            Audio audio = Audio.GetInstance;
            audio.Menu_Click.Play();
            LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(@"Menus\Textures2D\backgroundMenu"),
                                                           new MainMenuScreen(GameStateManagement.APP_NAME));
        }

        protected override void OnCancel(Microsoft.Xna.Framework.PlayerIndex playerIndex)
        {
            MediaPlayer.Resume();
            base.OnCancel(playerIndex);
        }

        
    }
}
